#ifndef XXfmUtility_h
#define XXfmUtility_h

#ifdef __cplusplus
extern "C" {
#endif
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libswscale/swscale.h>
    #include <libavdevice/avdevice.h>
    #include <libavutil/audio_fifo.h>
    #include <libavutil/avutil.h>
	#include <libswresample/swresample.h>
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif

    int xxfmUtility_duration(const char *path);

    int xxfmUtility_openDecodec(AVCodecContext **codecContex, AVStream *stream);
    int xxfmUtility_openVideoEncodec(AVCodecContext **codecContext, enum AVCodecID codecID, enum AVPixelFormat format, int width, int height, int framerate, int bitrate, int gop);
	int xxfmUtility_openAudioEncode(AVCodecContext **codecContext, enum AVCodecID codecID, enum AVSampleFormat format, int sampleRate, int channel);
	
	AVStream* xxfmUtility_findVideoStream(AVFormatContext *formatContext);
    AVStream* xxfmUtility_findAudioStream(AVFormatContext *formatContext);

    void xxfmUtility_transformTimeBase(AVFrame *frame, AVRational from, AVRational to);
    void xxfmUtility_transformTimeBaseFromAnotherFrame(AVFrame *fromFrame, AVRational from, AVFrame *toFrame, AVRational to);

	int xxfmUtility_initAudioFrame(AVFrame **frame, enum AVSampleFormat format, int nb_samples, int channel_layout);
	int xxfmUtility_initVideoFrame(AVFrame **frame, enum AVPixelFormat format, int width, int height);
	int xxfmUtility_initPacket(AVPacket **packet, const char *data, int length);
	int xxfmUtility_initFifo(AVAudioFifo **fifo, AVCodecContext *codecContext);

	int xxfmUtility_initResampler(struct SwrContext **swr, AVCodecContext *before, AVCodecContext *after);
	int xxfmUtility_initRescale(struct SwsContext **sws, AVCodecContext *before, AVCodecContext *after);

	int xxfmUtility_readAndDecode(AVFormatContext *formatContext, AVCodecContext *codecContext, AVFrame **output);
	int xxfmUtility_encode(AVFrame *frame, AVCodecContext *codecContext, AVPacket *output);
	int xxfmUtility_encodeAudioFrame(AVFrame *frame, AVCodecContext *codecContext, AVPacket *output, int *isEncoded, int isFirst);

#ifdef __cplusplus
}
#endif

#endif
